﻿@using KPIS.GERP.Models.ICM
@model Warehouse

@{
    ViewBag.Title = "คลังพัสดุ";
    ViewBag.Descr = "รายละเอียดคลังพัสดุ";

    ViewBag.SubTitle = "รายละเอียดคลังพัสดุ";

    var subModel = new WarehousePermit();
    subModel.WhId = Model.WhId;

    var service = new KPIS.GERP.WEB.GIMS.WarehouseService.WarehouseServiceClient();
    var WarehousePermitmodel
        = service.SelectWarehousePermit(new KPIS.GERP.Models.ICM.WarehousePermit { WhId = Model.WhId, RecordStatus = "!" + KPIS.GERP.Models.SYS.RecordStatus.DeletedStatus }
        , new[] {"Jobsite"});
}

<div class="block-button-menu-above">
    @Html.ButtonViewAll()
    @Html.ButtonEdit(new { id = Model.WhId })
    @Html.ButtonAdd()
    @Html.ButtonDelete(new { id = Model.WhId })
</div>

@Html.Partial("_DetailsForm")

<hr />

@using (Html.BeginForm("DeleteAllPermit", "Warehouse", FormMethod.Post, new { id = "indexForm" }))
{
    @Html.AntiForgeryToken()
    <div class="block-button-menu-above">
        @Html.ActionLink("เพิ่ม", "CreatePermit", "Warehouse"
        , new { WhId = Model.WhId }
        , new { id = "cmdCreateSub", role = "button", @class = "btn btn-small btn-success button-standard-width"
            , data_dialog_id = "aboutDialog", data_dialog_title = "เพิ่ม"})
        @Html.ButtonDeleteAll()
    </div>

    @Html.ValidationSummary(true, "", new {@class = "alert alert-error"})

    <div class="row-fluid">
        <div class="table-header span12">
            <div class="span10">
               หน่วยงานเบิกจ่าย
            </div>
            <div class="btn-group pull-right">
                <button data-toggle="dropdown" class="btn btn-small btn-primary dropdown-toggle">
                    Export
                    <i class="icon-angle-down icon-on-right"></i>
                </button>

                <ul class="dropdown-menu dropdown-danger" style="min-width: 80px;">
                    <li>
                        <a href="#"><i class="icon-file bigger-125"></i>  Word</a>
                    </li>

                    <li>
                        <a href="#"><i class="icon-table bigger-125"></i>  Excel</a>
                    </li>

                    <li>
                        <a href="#"><i class="icon-file-alt bigger-125"></i>  PDF</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>

    <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
        <thead>
            <tr>
                <th class="center" style="width: 50px;">
                    <label>
                        <input type="checkbox" />
                        <span class="lbl"></span>
                    </label>
                </th>
                <th>
                    ชื่อหน่วยงาน
                </th>
                <th></th>
            </tr>
        </thead>
    
        <tbody>
            @foreach (var m in WarehousePermitmodel)
            {
                <tr>
                    <td class="center">
                        <label>
                            <input type="checkbox" name="deleteIds" value="@(m.WarehousePermitId)" />
                            <span class="lbl"></span>
                        </label>
                    </td>

                    <td>@Html.DisplayFor(model => m.JobSite.Name)</td>
                    <td class="td-actions">
                        <div class="hidden-phone visible-desktop btn-group">
                            <a id = "cmdUpdateSub" href="/Warehouse/EditPermit/@(m.WarehousePermitId)" role="button"
                                class="btn btn-success btn-mini" data-dialog-id = "aboutDialog" data-dialog-title = "แก้ไข">
                                <i class="icon-edit bigger-120"></i>
                            </a>

                            @Html.ButtonDelete(new {WarehousePermitId = m.WarehousePermitId}, true, "DeletePermit")
                        </div>

                        <div class="hidden-desktop visible-phone">
                            <div class="inline position-relative">
                                <button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown">
                                    <i class="icon-caret-down icon-only bigger-120"></i>
                                </button>

                                <ul class="dropdown-menu dropdown-icon-only dropdown-yellow pull-right dropdown-caret dropdown-close">
                                    <li>
                                        <a id="cmdUpdateSubMini" href="@Url.Action("EditPermit","Warehouse")/@(m.WarehousePermitId)" class="tooltip-success" data-rel="tooltip" title="แก้ไข" data-placement="left">
                                            <span class="green">
                                                <i class="icon-edit"></i>
                                            </span>
                                        </a>
                                    </li>

                                    <li>
                                        <a href="@Url.Action("DeletePermit", "Warehouse")/@(m.WarehousePermitId)" class="tooltip-error" data-rel="tooltip" title="ลบ" data-placement="left">
                                            <span class="red">
                                                <i class="icon-trash"></i>
                                            </span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </td>
                </tr>
            }
        </tbody>
    </table>
}

<div id="modal" class="modal hide fade autosize" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="height:300px"></div>

@section scripts
{
    <script type="text/javascript">

        $(function () {
            $("form #indexForm").submit(function () {
                var currentForm = this;
                bootbox.confirm(function (result) {
                    var _result = result;
                    if (result) {
                        $.ajax({
                            url: "DeleteAllPermit",
                            type: "post",
                            dataType: "json",
                            data: $(currentForm).serialize(),
                            success: function (result) {
                                if (result.success) {
                                    location.reload();
                                } else {
                                    
                                }
                            }
                        });
                    }
                });
                return false;
            });

            var $modal = $('#modal');
            $('#cmdCreateSub, #cmdUpdateSub, #cmdUpdateSubMini').on('click', function (e) {
                e.preventDefault();
                var url = $(this).attr('href');
                $modal.html('<iframe width="100%" height="100%" frameborder="0" scrolling="no" allowtransparency="true" src="' + url + '"></iframe>');
                $modal.modal({
                    show: true
                });
            });

            $modal.on('hide', function () {
                $modal.empty(); // Clean up
                location.reload();
                //$("#table").trigger("reloadGrid");
            });

            $('.modal-body', this).css({ width: 'auto', height: 'auto', 'max-height': '100%' });
        });

    </script>
}